package com.yshkj.payment;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.validation.Validator;
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;

@SpringBootApplication
@EnableCaching
public class AdminApplication {

    public static void main(String[] args) {
        SpringApplication.run(AdminApplication.class, args);
    }

    /**
     * 手动配置validator验证器
     * 如果直接注册validator 则不会被spring-boot调用
     * 所以采用注册ConfigurableWebBindingInitializer 来完成调用
     *
     * @return ConfigurableWebBindingInitializer实例, 并设置总的validator
     */
    @Bean
    public ConfigurableWebBindingInitializer initializer(ApplicationContext applicationContext) {
        ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
        initializer.setValidator((Validator) applicationContext.getBean("webGlobalValidator"));
        return initializer;
    }
}
